Render animations in AMASS format in Maya

This tutorial shows how to render animations in Maya for AMASS dataset collection

Download dataset from AMASS collection

  • Download dataset: AMASS is a large database of human motion unifying different optical marker-based motion capture datasets by representing them within a common framework and parameterization. After opening an AMASS account, you may download the specific dataset you want from AMASS Download, and download the Dody Data in the SMPL+H column, for example.

e6a4c0c264b74ae8be3458bd28721a24

d72a7516624641b690426637c7d2118d

[1]:
# after downloading the dataset, unzip the tar.gz file, and assign the path for `npy` relative to the\
# the root folder of `GenMotion/src`
amass_npz_fname = '../thirdParty/accad/C2 - Run to stand_poses.npz'

Open Maya with socket server (AMASS)

b8e109da013c4412bae40f3f2773eada

  • Start a new Python script in the Script Editor and type the following command to open a [commandport] as a a local **socket server** with a PORT code e.g. 12345

import maya.cmds as cmds

# Open a command port with the default name "mayaCommand".
cmds.commandPort(n="localhost:12345")

Import FBX model into Maya (AMASS)

In Maya scene, import the downloaded SMPL+H fbx file; (or you may refer to Meshcapade Wiki for more information with the SMPL format)

9b1f2838aa474336ae3b4931a16d008a

Now everything is ready to make animation from scripts in Maya.

428e66ecfd434fd0919e56bed9922d3d

In Maya scene view, you will have see the skeleton prefix (e.g. f_avg) in the Outliner view, the FBX with skin and skeleton in View Port, and the socket server opened by the Script Editor.

Animation (AMASS)

Now we are ready to make the animation from Python scripts.

[3]:
# import packages
import numpy as np
from tqdm.auto import tqdm

# import GenMotion modules

from genmotion.dataset.amass_params import SMPL_H_SKELETON # recognize the skeleton type as SMPL_H
from genmotion.render.maya.utils import MayaController
[4]:
# load body data from npz file
bdata = np.load(amass_npz_fname)
[5]:
# Set up Maya Controller (socket client) with PORT number
mc = MayaController(PORT=12345)
[6]:
## Test Maya command by setting the key frame at timeline
# mc.SetCurrentTimeFrame(10)

## Have a look at the body data information
# print('Data keys available:%s'%list(bdata.keys()))
[7]:
# Get the frame rate of from the body data
print("framerate:", bdata['mocap_framerate'])
framerate: 120.0
[8]:
# Set one frame for the animation
def SetOneFrame(frame, body_data, joints_info_list: list, joint_prefix = "f_avg_"):
    '''Set one maya frame from load data

    :param frame: int
    :param body_data: array
    :param joints_info_list: list
    :return:
    '''
    #  set current time frame
    mc.SetCurrentTimeFrame(frame)

    for i in range(0,len(joints_info_list)):
        # get rotation from body data
        rotateX, rotateY, rotateZ = np.rad2deg(body_data['poses'][frame][i*3:(i+1)*3])

        # get joint name
        joint_name = joint_prefix + joints_info_list[i]

        # if i == 0, set root translation
        if i == 0:
            joint_name = joint_prefix + "root"
            translateX,translateY,translateZ = body_data['trans'][frame]
            mc.SetObjectAttribute(joint_name, "translateX", translateX)
            mc.SetObjectAttribute(joint_name, "translateY", translateY)
            mc.SetObjectAttribute(joint_name, "translateZ", translateZ)

        # set rotation for joints
        mc.SetObjectAttribute(joint_name, "rotateX", rotateX)
        mc.SetObjectAttribute(joint_name, "rotateY", rotateY)
        mc.SetObjectAttribute(joint_name, "rotateZ", rotateZ)

        mc.SetCurrentKeyFrameForPositionAndRotation(joint_name)
        #break
[19]:
# Now we maker animation for every 10 frame
frame_interval = 10
for frame in tqdm(range(0, len(bdata["poses"]), frame_interval)):
    SetOneFrame(frame, bdata, SMPL_H_SKELETON)
100%|██████████| 64/64 [00:42<00:00,  1.52it/s]

Now we are able to see the animation in Maya!

2fbb1ea9a5c14c3094705bf81021ea1a